
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:flutter_wan_android/res/colors.dart';

class LoadingView extends StatelessWidget{


  @override
  Widget build(BuildContext context) {
    return  Container(
      width: double.infinity,
      height: double.infinity,
      child: Center(
          child: SizedBox(
            height: 150.0,
            width: 150.0,
            child: Card(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                    width: 50.0,
                    height: 50.0,
                    child: SpinKitFadingCube(
                      color: Colors.red,
                      size: 30.0,
                    ),
                  ),
                  Padding(padding: EdgeInsets.all(8)),
                  Container(
                    child: Text('loading'),
                  )
                ],
              ),
            ),
          )),
    );
  }


  static Widget buildLoading(BuildContext context){
    return LoadingView().build(context);
  }

}


class ErrorView extends StatelessWidget{
  
  final String error;

  final VoidCallback onTap;

  const ErrorView({Key key, this.error, this.onTap}) : super(key: key);
  
  
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Icon(Icons.error,
          size: 80,),
          Padding(padding: EdgeInsets.all(6)),
          Text(error.isEmpty?'加载失败':error),

          Padding(padding: EdgeInsets.only(top: 30)),
          
          InkWell(
            child: OutlineButton(onPressed: null, child: Text("重新加载",style:
              TextStyle(color: XColors.mainTabUnSelectedColor),)) ,
            
            onTap: onTap,
          )
          
        ],
      ),
    );
  }
  
}